﻿using IDLETD.WhyMath;
using IDLETD.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace IDLETD.Agent
{
    public class CrashAgent
    {
        public ObservableCollection<BaseGameObject> ObjectList = new ObservableCollection<BaseGameObject>();

        public BaseGameObject Onwer { get; set; }

        public BaseGameObject CheckCrash()
        {
            foreach (var item in ObjectList)
            {
                if (item == Onwer) continue;
                if (item.Type != ObjectType.怪物) continue;
                if (item.IsDead) continue;
                //if (Math.Pow(Onwer.X - item.X, 2) + Math.Pow(Onwer.Y - item.Y, 2) <= Math.Pow(Onwer.Range + item.X, 2))
                //    return item;
                Circle r1 = new Circle(Onwer.X + Onwer.Width / 2, Onwer.Y + +Onwer.Height / 2, Onwer.Range);
                Rect r2 = new Rect(item.X, item.Y, item.Width, item.Height);
                if (r1.Intersects(r2)) return item;
            }
            return null;
        }

        public ObservableCollection<BaseGameObject> CheckInRange()
        {
            ObservableCollection<BaseGameObject> list = new ObservableCollection<BaseGameObject>();
            foreach (var item in ObjectList)
            {
                if (item == Onwer) continue;
                Circle r1 = new Circle(Onwer.X + Onwer.Width / 2, Onwer.Y + +Onwer.Height / 2, Onwer.Range);
                Rect r2 = new Rect(item.X, item.Y, item.Width, item.Height);
                if (r1.Intersects(r2)) list.Add(item);
            }
            return list;
        }
    }
}
